package com.ruoyi.pad.service.impl;


import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.pad.domain.KyPadInfo;
import com.ruoyi.pad.mapper.KyPadInfoMapper;
import com.ruoyi.pad.service.IKyPadInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 平板信息Service业务层处理
 */
@Service
public class KyPadInfoServiceImpl implements IKyPadInfoService {
    @Resource
    private KyPadInfoMapper kyPadInfoMapper;

    /**
     * 查询平板信息
     *
     * @param padId 平板信息主键
     * @return 平板信息
     */
    @Override
    public KyPadInfo selectKyPadInfoByPadId(Long padId) {
        return kyPadInfoMapper.selectKyPadInfoByPadId(padId);
    }

    /**
     * 查询平板信息列表
     *
     * @param kyPadInfo 平板信息
     * @return 平板信息
     */
    @Override
    public List<KyPadInfo> selectKyPadInfoList(KyPadInfo kyPadInfo) {
        return kyPadInfoMapper.selectKyPadInfoList(kyPadInfo);
    }

    /**
     * 新增平板信息
     *
     * @param kyPadInfo 平板信息
     * @return 结果
     */
    @Override
    public int insertKyPadInfo(KyPadInfo kyPadInfo) {
        kyPadInfo.setCreateTime(DateUtils.getNowDate());
        return kyPadInfoMapper.insertKyPadInfo(kyPadInfo);
    }

    /**
     * 修改平板信息
     *
     * @param kyPadInfo 平板信息
     * @return 结果
     */
    @Override
    public int updateKyPadInfo(KyPadInfo kyPadInfo) {
        kyPadInfo.setUpdateTime(DateUtils.getNowDate());
        return kyPadInfoMapper.updateKyPadInfo(kyPadInfo);
    }

    /**
     * 批量删除平板信息
     *
     * @param padIds 需要删除的平板信息主键
     * @return 结果
     */
    @Override
    public int deleteKyPadInfoByPadIds(Long[] padIds) {
        return kyPadInfoMapper.deleteKyPadInfoByPadIds(padIds);
    }

    /**
     * 删除平板信息信息
     *
     * @param padId 平板信息主键
     * @return 结果
     */
    @Override
    public int deleteKyPadInfoByPadId(Long padId) {
        return kyPadInfoMapper.deleteKyPadInfoByPadId(padId);
    }


    /**
     * 根据sn获取平板信息
     * @param padSn
     * @return
     */
    @Override
    public KyPadInfo selectKyPadInfoByPadSn(String padSn) {
        return kyPadInfoMapper.selectKyPadInfoByPadSn(padSn);
    }

    /**
     * 根据设备号获取平板列表信息
     * @param devNum
     * @return
     */
    @Override
    public List<KyPadInfo> selectKyPadInfoByDevNum(String devNum) {
        return kyPadInfoMapper.selectKyPadInfoByDevNum(devNum);
    }

    /**
     * 批量插入平板信息
     * @param padInfoList
     * @return
     */
    @Override
    public int batchInsert(List<KyPadInfo> padInfoList) {
        return kyPadInfoMapper.batchInsert(padInfoList);
    }

    /**
     * 判断是否已经绑定平板
     * @param padSn
     * @return
     */
    @Override
    public boolean haveBind(String padSn) {
        Integer count = kyPadInfoMapper.selectExistPadByPadSn(padSn);
        return count!=null && count.intValue() > 0;
    }

    /**
     * 根据设备号和sn判断是否绑定平板
     * @param devNum
     * @param padSn
     * @return
     */
    @Override
    public boolean haveBind(String devNum, String padSn) {
        Integer count = kyPadInfoMapper.findByDevNumAndPadSn(devNum, padSn);
        System.out.println("devNum: " + devNum);
        System.out.println("padSn: " + padSn);
        System.out.println("count: " + count);
        return count !=null  && count.intValue() > 0;
    }

    /**
     * 删除平板信息
     *
     * @param padSn
     * @return 结果
     */
    @Override
    public int deleteKyPadInfoByPadSn(String padSn) {
        return kyPadInfoMapper.deleteKyPadInfoByPadSn(padSn);
    }
}
